import { http, fetchPost } from "@/utils/http";
import { v4 as uuidv4 } from "uuid";

export function myCustomerAPI(
  data = { searchKey: "", pageSize: 20, pageNumber: 1, startTime: "2020-01-01" }
) {
  return http.request({
    url: `/rest/api/customer/mycustomer/list`,
    method: "POST",
    data
  });
}

/// 获取公司基本信息
export function getCompanyBaseInfo(companyId) {
  return http.request({
    url: `/rest/api/user/company/baseinfo/${companyId}`,
    method: "GET"
  });
}

/// 获取公司基本信息 - 招聘信息
export const getCompanyRecruitmentInfo = companyId => {
  return http.request({
    url: `/rest/api/user/company/baseinfo/${companyId}/hr`,
    method: "GET"
  });
};

// 获取公司的企业关系
export const getCompanyBranches = companyId => {
  return http.request({
    url: `/rest/api/user/company/branches/${companyId}`,
    method: "GET"
  });
};

/// 公司的行业信息
export const getCompanyIndustry = companyId => {
  return http.request({
    url: `/rest/api/user/company/industry/${companyId}`,
    method: "GET"
  });
};

/// 点赞
export const setLikeState = (
  parameter = { companyId: null, type: null, like: null }
) => {
  const { companyId, type, like } = parameter;
  return http.request({
    url: `/rest/api/user/company/${companyId}/type/${type}/like/${like}`,
    method: "POST"
  });
};

/// 获取整个点赞配置
export const getBeLikeData = companyId => {
  return http.request({
    url: `/rest/api/user/company/${companyId}`,
    method: "GET"
  });
};

/// 设置收藏状态
export const setCollectedStatus = (
  parameter = { companyId: null, collected: null }
) => {
  const { companyId, collected } = parameter;
  return http.request({
    url: `/rest/api/user/company/${companyId}/collected/${collected}`,
    method: "POST"
  });
};

/// bing检索
export const searchBingAPI = searchKey => {
  const data = {
    qid: uuidv4(),
    type: "COMPANY_NAME",
    q: searchKey
  };
  return http.request({
    url: `/rest/api/company/online/search`,
    method: "POST",
    useOriginRes: true,
    data
  });
};

/// bing 关键词
export const searchBingContentAPI = searchKey => {
  const data = {
    qid: uuidv4(),
    type: "COMPANY_NAME",
    q: searchKey
  };
  return http.request({
    url: `/rest/api/company/online/search/content`,
    method: "POST",
    data
  });
};

// 取得客户沟通记录
export const customerVisitRecordAPI = (customerId, data) => {
  return http.request({
    url: `/rest/api/customer/${customerId}/meetings`,
    method: "POST",
    data
  });
};

// 取得客户风险信息
export const getCustomerRiskAPI = customerId => {
  return http.request({
    url: `/rest/api/customer/${customerId}/risks`,
    method: "GET"
  });
};

// 取得客户参会人
export const customerAttendeeAPI = (customerId, data) => {
  return http.request({
    url: `/rest/api/aichat/customer/${customerId}/contacts`,
    method: "POST",
    data,
    disableProgress: true
  });
};

// 取得客户待办
export const getCustomerTodoListAPI = (customerId, data) => {
  return http.request({
    url: `/rest/api/customer/${customerId}/todos`,
    method: "POST",
    data
  });
};
// 更新客户待办
export const updateCustomerTodoStatusAPI = (confId, todoId, data) => {
  return http.request({
    url: `/rest/api/conference/${confId}/todo/${todoId}`,
    method: "PUT",
    data
  });
};

// 取得客户竞争对手
export const getCustomerCompetitorsAPI = (customerId, data) => {
  return http.request({
    url: `/rest/api/customer/${customerId}/competitors`,
    method: "POST",
    data
  });
};

// 取得竞争对手详情
export const getCompetitorsDetailAPI = (customerId, competitorId) => {
  return http.request({
    url: `/rest/api/aichat/customer/${customerId}/competitor/${competitorId}/analysis`,
    method: "GET"
  });
};

// 获取客户MEDDIC
export const getCustomerMeddicAPI = customerId => {
  return http.request({
    url: `/rest/api/meddic/customer/${customerId}`,
    method: "GET"
  });
};

// 更新客户MEDDIC
export const updateCustomerMeddicAPI = data => {
  return http.request({
    url: `/rest/api/meddic/`,
    method: "PUT",
    data,
    disableProgress: true
  });
};

// 重新生成客户MEDDIC
export const remakeCustomerMeddicAPI = customerId => {
  return http.request({
    url: `/rest/api/conference/report/customer/${customerId}/meddic`,
    method: "GET",
    timeout: 6000000,
    disableToast: true
  });
};

// 获取客户信息
export const getCustomCustomerInfoAPI = customerId => {
  return http.request({
    url: `/rest/api/customer/${customerId}`,
    method: "GET"
  });
};

// 删除客户
export const removeCustomCustomerAPI = customerId => {
  return http.request({
    url: `/rest/api/customer`,
    method: "DELETE",
    data: {
      source: 1,
      ids: [customerId]
    }
  });
};

// 获取客户详情商机列表 opportunity/customer/list
export const getOpportunityListAPI = (data = { customerId: "", pageNumber: 1, pageSize: 20 }) => {
  return http.request({
    url: `/rest/api/opportunity/customer/list`,
    method: "POST",
    data
  });
};

// 获取我的商机列表
export const getMyOpportunityListAPI = (data = { pageNumber: 1, pageSize: 20 }) => {
  return http.request({
    url: `/rest/api/opportunity/list`,
    method: "POST",
    data
  });
};